<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test"></div>
    <script src="../demo1/js/react.development.js"></script>
    <script src="../demo1/js/react-dom.development.js"></script>
    <script src="../demo1/js/babel.min.js"></script>
    <script src="./js/prop-types.js"></script>
    <script type="text/babel">
        class Super extends React.Component{

            state = {carName:'宝马'}
            
            changeCar = ()=>{
                this.setState({
                    carName:'奥迪'
                })
            }

            render() {
                return (
                    <div>
                        <h3>我是super</h3>
                        <button onClick={this.changeCar}>换车</button>
                        <br/>
                        <Sub carName={this.state.carName} />
                    </div>
                )
            }
        }
        class Sub extends React.Component{

            // 子组件将要接收新的props调用 (第一次不算)
            componentWillReceiveProps(props){
                console.log('=======', props);
            }

            shouldComponentUpdate(){
                console.log(' sub ---> shoulComponentUpdate');
                return true
            }

            ComponentWillUpdate(){
                console.log(' sub ---> ComponentWillUpdate');
            }

            componentDidUpdate(){
                console.log(' sub ---> componentDidUpdate');
            }
            
            render() {
                const {carName} = this.props
                return (
                    <div>
                        <h3>我是sub</h3>
                         <h4>{carName}</h4>
                    </div>
                )
            }
        }

        ReactDOM.render(< Super />, document.querySelector('#test'))
        
    </script> 
</body>
</html>